/**
 * 
 */
package sudoku.ui;

import javax.swing.JDialog;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

import sudoku.util.Data;
import sudoku.util.Language;


/**
 * @author Romet
 *
 */
public class HistoryUI{

	private volatile Data data;
	private volatile SudokuUI m2ng;
	private volatile Language language;
	
	/**
	 * Seadistab mängude ajaloo kasutajaliidese.
	 * @param data andmete klassi isend
	 * @param m2ng põhiakna graafika klassi isend
	 */
	public HistoryUI(Language language, Data data, SudokuUI m2ng){
		this.language = language;
		this.data = data;
		this.m2ng = m2ng;
	}
	
	/**
	 * Teeb mängude ajaloo akna.
	 */
	public void ajalugu(){
		String[] strings = new String[data.getAjalugu().size()];
		for (int i = 0; i < strings.length; i++) {
			strings[i] = (String)data.getAjalugu().get(i);
		}
		JList list = new JList(strings);
		if (strings.length > 20){
			list.setVisibleRowCount(20);
		}
		else{
			list.setVisibleRowCount(strings.length);
		}
		JScrollPane scrollPane = new JScrollPane(list);
		JOptionPane pane = new JOptionPane(scrollPane);
		pane.setOptionType(JOptionPane.PLAIN_MESSAGE);
		JDialog dialog = pane.createDialog(this.m2ng, this.language.getHistory_title());
		dialog.setVisible(true);
	}
}
